package cn.sintang.redis.utils;

import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @author sintang
 * @date 2018-07-12 21:54
 **/
public class JedisUtils {
     public static Jedis jedis;
     static {
         jedis = new Jedis("127.0.0.1",6381);
     }

    public static void main(String[] args) {
        jedis.set("testStr","hello");
        System.out.println(jedis.get("testStr"));

        // append，若key存在就在value上新增，如果不存在就是set
        jedis.append("testStr"," world");
        System.out.println(jedis.get("testStr"));

        System.out.println("判断key存在与否："+jedis.exists("testStr1"));

        // 设置多个key-value值，key1,value1,key2,value2
        jedis.mset("name1","我是name1","name2","我是name2");
        // 获取多个key的值，key1,key2
        List<String> mgetVals = jedis.mget("name1", "name2");
        for(String val : mgetVals){
            System.out.println(val);
        }
    }
}
